-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix trial end check #5772
base: main
Are you sure you want to change the base?
fix trial end check #5772
Conversation
admin/jobs/river/trial_checks.go
Outdated
@@ -89,7 +89,7 @@ func (w *TrialEndCheckWorker) Work(ctx context.Context, job *river.Job[TrialEndC | |||
} | |||
|
|||
func (w *TrialEndCheckWorker) trialEndCheck(ctx context.Context) error { | |||
onTrialOrgs, err := w.admin.DB.FindBillingIssueByTypeNotOverdueProcessed(ctx, database.BillingIssueTypeOnTrial) | |||
onTrialOrgs, err := w.admin.DB.FindBillingIssueByType(ctx, database.BillingIssueTypeOnTrial) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be selecting too many rows. One way to avoid is to use something like next_check_time
. Index on it and always fetch next_check_time < now and type=...
.
- Set it to
now + trial_period - ending_soon_period
during creation initially. - In
TrialEndingSoonWorker
after success set it tonext_check_time += ending_soon_period
. - Here in
TrialEndCheckWorker
after success we could delete it as we are doing already.
Note that we would also need a sub type on top of this to not select fresh subscriptions in TrialEndCheckWorker
.
One advantage is that we can use this for other types apart from trial based issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think its worth the complexity, want to keep it as simple as possible. We anyways typically have page sizes of around 100 or 1000 elsewhere in the code so don't think there will be orgs more than this on trial and we skip orgs for which trial not ended in the for loop.
Its a background job so may be not a big deal and not all checks are time based so next_check_time
field will not be generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one optimization where trial end check will only fetch processed on trial issues thus only orgs which are within a week of trial end date.
on-trial issue type is marked as processed after sending trial ending soon email so its not checked in trial end worker. Fetching all orgs that have on-trial issue irrespective of processed or not and deleting the issue and raising trial ended issue in trial end check job.